
var app = getApp(); 
const api = require('../../../api/index.js') 
Page({
  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if ( !oppid){
      app.Logins();
    }
    let oppid = wx.getStorageSync('openid').openid;
    console.log(options)
    let data = {};
    data.openid_wechat = oppid;
    data.name = options.pNmae;
    data.mobile = options.phones;
    data.num = options.num;
   
    api.F9F(data, (res) => {
      console.log(res);
      this.data.order_sn = res.data.result.order_sn;
      let dataPay = res.data.result;
      console.log(dataPay)
      this.pay(dataPay);
    })
  },
  pay: function (dataPay){
    console.log(dataPay)
    let thes = this;
    wx.requestPayment({
      'timeStamp': dataPay.timeStamp,
      'nonceStr': dataPay.nonceStr,
      'package': dataPay.package,
      'signType': 'MD5',
      'paySign': dataPay.paySign,
      'success': function (res) {
        wx.navigateTo({
          url: '/pages/activity/succe/succe?order_sn='+thes.data.order_sn,
        })
      },
      'fail': function (res) {
        wx.showToast({
          title: '支付失败',
          icon: 'none'
        })
        setTimeout(function(){
          wx.navigateBack({//返回
            delta: 1
          })
        },1000)
        console.log('交钱失败')
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },
 
})
